package tech.fangsong.im.core.protocol;


/**
 * 消息定义，定长包头+变长包体
 */
public class ImMsg {
    /**
     *  版本
     */
    private short version;
    /**
     * 定长包头长度
     */
    public static final int HEADER_LENGTH = 1 + 2 + 1 + 1 + 1 + 8 + 4;

    /**
     * StartMagic
     */
    public static final byte HEADER_MAGIC = 0X7F;

    /**
     * 协议族
     */
    private byte family;

    /**
     *  协议
     */
    private byte cmd;

    /**
     *  消息类型  0-R包  1-A包  2-N包
     */
    private byte type;

    /**
     * 消息序列，严格递增，可以不连续
     */
    private long sequence;

    /**
     * payload长度
     */
    private int payloadLength;

    /**
     * 消息的内容
     */
    private byte[] payload;

    public static int getHeaderLength(){
        return HEADER_LENGTH;
    }

    public static byte getHeaderMagic(){
        return HEADER_MAGIC;
    }

    public byte getFamily() {
        return family;
    }

    public void setFamily(byte family) {
        this.family = family;
    }

    public byte getCmd() {
        return cmd;
    }

    public void setCmd(byte cmd) {
        this.cmd = cmd;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public short getVersion() {
        return version;
    }

    public void setVersion(short version) {
        this.version = version;
    }

    public long getSequence() {
        return sequence;
    }

    public void setSequence(long sequence) {
        this.sequence = sequence;
    }

    public int getPayloadLength() {
        return payloadLength;
    }

    public void setPayloadLength(int payloadLength) {
        this.payloadLength = payloadLength;
    }

    public byte[] getPayload() {
        return payload;
    }

    public void setPayload(byte[] payload) {
        this.payload = payload;
    }
}
